package com.ang.controller;

import com.ang.mapper.UserMapper;
import com.ang.model.UserModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TestController {

    @Autowired
    private UserMapper userMapper;

    /**
     * 读写分离测试：读数据
     * 连接的是代理库，会查询从库中的数据
     */
    @RequestMapping("/testSelectAll")
    public List<UserModel> testSelectAll(){
        List<UserModel> users = userMapper.selectList(null);
        return users;
    }

    /**
     * 读写分离测试：写测试
     * 主表和从表都会添加数据
     */
    @RequestMapping("/testWriteUser")
    public int testWriteUser(){
        UserModel userModel = new UserModel();
        userModel.setUname("test");
        int insert = userMapper.insert(userModel);
        return insert;
    }
}
